package game.cube;

import game.cube.scene.Scene1;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLSurfaceView;

public class GL_Renderer implements GLSurfaceView.Renderer {
	private Scene1[] mScene;
	private int sceneIndex = 0;
	private Shader mShader;

	private boolean mOnce = true;
	public GL_Renderer(Activity activity, int width, int height) {
		mScene = new Scene1[2];//Interface[2];
		mScene[0] = new Scene1(activity, width, height);
		mScene[1] = new Scene1(activity, width, height);
		mShader = new Shader();

	}
	@Override
	public void onDrawFrame(GL10 gl) {
		if (mOnce) {
			mShader.initialize();
			mScene[sceneIndex].initialize();
			mOnce = false;
		}
		mScene[sceneIndex].update(sceneIndex);
		if (sceneIndex == 0) {
			mShader.drawPoint(mScene[sceneIndex].getPoint(), mScene[sceneIndex].getCamera());
		} else if (sceneIndex == 1) {
			mShader.draw(mScene[sceneIndex].getShape(), mScene[sceneIndex].getCamera());
		}
		if (mScene[sceneIndex].isChangeScene()) {
			if (sceneIndex == 0) {
				sceneIndex = 1;
			} else {
				sceneIndex = 0;
			}
			mOnce = true;
		}

//		mShader.drawTree(mScene.getTree());
	}
	@Override
	public void onSurfaceChanged(GL10 unused, int width, int height) {
		mShader.setViewPort(width, height);
	}
	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	}
}